Component({
    options:{
        styleIsolation: 'apply-shared',
    },
    properties: {},
    data: {
        show:false,
        title: "用户隐私保护提示",
        desc1: "感谢您使用本商城，您使用本商城前应当阅井同意",
        urlTitle: "《用户隐私保护指引》",
        desc2: "当您点击同意并开始时用产品服务时，即表示你已理解并同息该条款内容，该条款将对您产生法律约束力。如您拒绝，将无法进入商城。",
    },
    lifetimes:{
        attached() {
            if (wx.getPrivacySetting) {
                wx.getPrivacySetting({
                    success: res => {
                        console.log("是否需要授权：", res.needAuthorization, "隐私协议的名称为：", res.privacyContractName)
                        if (res.needAuthorization) {
                            this.showDialog()
                        } else{
                            // 不需要授权
                        }
                    },
                    fail: () => { },
                    complete: () => { },
                })
            } else {
                // 低版本基础库不支持 wx.getPrivacySetting 接口，隐私接口可以直接调用
            }
        }
    },
    methods: {
        showDialog() {
            this.setData({
                show:true,
            });
        },

        closeDialog() {
            this.setData({
                show:false,
            });
        },

        openPrivacyContract() {
            wx.openPrivacyContract({
                success: res => {
                    console.log('openPrivacyContract success')
                },
                fail: res => {
                    console.error('openPrivacyContract fail', res)
                }
            })
        },

        handleAgree(e) {
            this.closeDialog()
        },

        handleDisagree(e) {
            this.closeDialog()
            wx.exitMiniProgram()
        },
    }
});
